package javafx179labs.sorokin.lab4;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.animation.Timeline;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.animation.KeyFrame;
import javafx.animation.transition.*;

//При клике на машинку, машинка начинает ехать.
//Как только подъезжает к человеку останавливается.
//Кликнув по человеку машинка сбивает его, разрывая на куски( мясо прилогается(вроде сердце и печень))
//Извиняюсь, что закомитил все так поздно

/**
 * @author Krazyzy
 */

var meat = ImageView
{
    image: Image { url: "{__DIR__}meat.png" }
    x: 5580
    y: 70
    }

var meat2 = ImageView
{
    image: Image { url: "{__DIR__}meat2.png" }
    x: 5570
    y: 70
    }

var head = ImageView
{
    image: Image { url: "{__DIR__}head.png" }
    x: 5550
    y: 50
    }

    var tors: ImageView = ImageView
{
    image: Image { url: "{__DIR__}tors.png" }
    x: 5550
    y: 50
    onMouseClicked: function( e: MouseEvent ):Void {
    timeline2.playFromStart();
    rotTransition3.play();
    rotTransition4.play();
    }
}

    var legs = ImageView
{
    image: Image { url: "{__DIR__}legs.png" }
    x: 5550
    y: 50
    }

var road = ImageView
{
    image: Image { url: "{__DIR__}road.jpg" }
    x: 0
    y: 0
}

var wheel1 = ImageView
{
    image: Image { url: "{__DIR__}wheel1.png" }
    x: 198
    y: 271
}

var rotTransition1 = RotateTransition {
        duration: 0.3s node: wheel1
        byAngle: 360 repeatCount:34 autoReverse: false
        }



var wheel2 = ImageView
{
    image: Image { url: "{__DIR__}wheel2.png" }
    x: 515
    y: 298
}

var rotTransition2 = RotateTransition {
        duration: 0.3s node: wheel2
        byAngle: 360 repeatCount:34 autoReverse: false
    }

var car = ImageView
{
    image: Image { url: "{__DIR__}car.png" }
    x: 70
    y: 70
   onMouseClicked: function( e: MouseEvent ):Void {
        rotTransition1.play();
        rotTransition2.play();
        timeline.playFromStart();
    }
}


var light1 = ImageView
{
    image: Image { url: "{__DIR__}light.png" }
    x: 20
    y: 50
    }

var light2 = ImageView
{
    image: Image { url: "{__DIR__}light.png" }
    x: 500
    y: 50
}

var light3 = ImageView
{
    image: Image { url: "{__DIR__}light.png" }
    x: 1000
    y: 50
}

var timeline: Timeline = Timeline {
    repeatCount: Timeline.INDEFINITE
    autoReverse: false
    keyFrames : [
        KeyFrame {
            time : 1s
            values : [
               light1.x => -80,
               light2.x => 400,
               light3.x => 900
               ]
               }
       
                KeyFrame {
            time : 2s
            values : [
               light1.x => -180,
               light2.x => 300,
               light3.x => 800
               ]
       }
       
                       KeyFrame {
            time : 3s
            values : [
               light1.x => -280,
               light2.x => 200,
               light3.x => 700
               ]
       }
       
                              KeyFrame {
            time : 4s
            values : [
               light1.x => -380,
               light2.x => 100,
               light3.x => 600
               ]
       }

       KeyFrame {
            time : 4.0000000000000000001s
            values : [
               light1.x => 1000,
               ]
       }
       
                              KeyFrame {
            time : 5s
            values : [
               light1.x => 1000,
               light2.x => 0,
               light3.x => 500
               ]
       }
       
       
                              KeyFrame {
            time : 6s
            values : [
               light1.x => 900,
               light2.x => -100,
               light3.x => 400
               ]
       }
       
       
                              KeyFrame {
            time : 7s
            values : [
               light1.x => 800,
               light2.x => -200,
               light3.x => 300
               ]
       }
       
       
                              KeyFrame {
            time : 8s
            values : [
               light1.x => 700,
               light2.x => -300,
               light3.x => 200
               ]
       }
       
       
                              KeyFrame {
            time : 9s
            values : [
               light1.x => 600,
               light2.x => -400,
               light3.x => 100
               ]
       }

                                     KeyFrame {
            time : 9.0000000000000000001s
            values : [
               light2.x => 1000,
               ]
       }
       
       
                              KeyFrame {
            time : 10s
            values : [
               light1.x => 500,
               light2.x => 900,
               light3.x => 0
               ]
       }

                                KeyFrame {
            time : 10s
            values : [
               meat.x => 880,
               meat2.x => 870,
               head.x => 850,
               legs.x => 850,
               tors.x => 850
               ]
               action: function (): Void {
                  timeline.stop();
       }
                }


                                KeyFrame {
            time : 30s
            values : [
               meat.x => 880,
               meat2.x => 870,
               head.x => 850,
               legs.x => 850,
               tors.x => 850
               ]
                }

        ]
        }

        var rotTransition3 = RotateTransition {
        duration: 0.3s node: wheel1
        byAngle: 360 repeatCount:4 autoReverse: false
    }

    var rotTransition4 = RotateTransition {
        duration: 0.3s node: wheel2
        byAngle: 360 repeatCount:4 autoReverse: false
    }

    var timeline2: Timeline = Timeline {
    repeatCount: Timeline.INDEFINITE
    autoReverse: false
    keyFrames : [

KeyFrame {
            time : 1s
            values : [
               meat.x => 580,
               meat2.x => 570,
               head.x => 550,
               legs.x => 550,
               tors.x => 550,
               light1.x => 200,
               light2.x => 600,
               light3.x => -300
               ]
       }

       KeyFrame {
            time : 1.1s
            values : [
               meat.x => 580,
               meat2.x => 570,
               head.x => 550,
               legs.x => 550,
               tors.x => 550,
               light1.x => 200,
               light2.x => 600,
               light3.x => -300
               ]
       }

              KeyFrame {
            time : 1.2s
            values : [
               meat.x => 570,
               meat2.x => 560,
               head.x => 550,
               tors.x => 550,
               meat.y => 70,
               meat2.y => 70,
               head.y => 50,
               tors.y => 50,
               legs.x => 650
               ]
       }

       KeyFrame {
            time : 5s
            values : [
               meat.x => 50,
               meat2.x => 70,
               head.x => 100,
               tors.x => 200,
               meat.y => 300,
               meat2.y => 300,
               head.y => 300,
               tors.y => 200,
               ]
               action: function (): Void {
                  timeline2.stop();
       }
       }

       KeyFrame {
            time : 50s
            values : [
               meat.x => 50,
               meat2.x => 70,
               head.x => 100,
               tors.x => 200,
               meat.y => 300,
               meat2.y => 300,
               head.y => 300,
               tors.y => 200,
               ]
       }
            ]
        }
    

Stage {
    title: "Application title"
    width: 1100
    height: 430
    scene: Scene {
        content: [
            road, light1, light2, light3, car, wheel1,
            wheel2,meat, meat2, head, tors, legs
           ]
    }
}

